//socket.js
var ws;
function initializeSocket()
{
	ws=new WebSocket('ws://127.0.0.1:8080');
	ws.onopen=function(msg){
		console.log('websocket opened');
	};
	ws.onmessage=function(message){
		console.log('recive message:'+message.data);		
	};
	ws.onerror=function(error){
		console.log('error:'+error.name+error.number);
	};
	ws.onclose=function(){
		console.log('websocket closed');
	};
	
}
function sendMessage(){
	console.log('sending a message...');
	ws.send('hello websocket');
}
window.onbeforeunload=function(){
	ws.close();
};